/**
 * 
 */
package com.dalonedrow.module.hq.ui.views;

import com.badlogic.gdx.Input.Buttons;
import com.badlogic.gdx.Input.Keys;
import com.dalonedrow.engine.sprite.base.SimplePoint;
import com.dalonedrow.engine.sprite.base.SpriteBase;
import com.dalonedrow.engine.sprite.base.SpriteImageObject;
import com.dalonedrow.engine.sprite.base.SpriteImageObjectFactory;
import com.dalonedrow.engine.sprite.impl.BasicSpriteObject;
import com.dalonedrow.engine.systems.JOGLErrorHandler;
import com.dalonedrow.engine.systems.base.Action;
import com.dalonedrow.engine.systems.base.InputEvent;
import com.dalonedrow.engine.systems.base.Interactive;
import com.dalonedrow.engine.systems.base.Interface;
import com.dalonedrow.engine.systems.base.ProjectConstants;
import com.dalonedrow.engine.ui.base.GuiComponent;
import com.dalonedrow.engine.ui.base.View;
import com.dalonedrow.engine.ui.base.border.AbstractHighlightBorder;
import com.dalonedrow.engine.ui.base.border.BorderFactory;
import com.dalonedrow.engine.ui.base.panel.LandscapePagePanel;
import com.dalonedrow.engine.ui.base.panel.PagePanel;
import com.dalonedrow.engine.ui.base.panel.Panel;
import com.dalonedrow.engine.ui.base.panel.PortraitPagePanel;
import com.dalonedrow.engine.ui.impl.Button;
import com.dalonedrow.engine.ui.impl.Label;
import com.dalonedrow.engine.ui.impl.UIFactory;
import com.dalonedrow.engine.ui.impl.border.H1SelectionBorder;
import com.dalonedrow.globalvariables.constants.hq.GlobalConstants;
import com.dalonedrow.module.hq.DawnQuestGame;
import com.dalonedrow.module.hq.bus.heroes.Akron;
import com.dalonedrow.module.hq.bus.heroes.Galadrus;
import com.dalonedrow.module.hq.bus.heroes.Strom;
import com.dalonedrow.module.hq.bus.heroes.Zull;
import com.dalonedrow.module.hq.rpg.HQInteractiveObject;
import com.dalonedrow.module.hq.systems.HQController;
import com.dalonedrow.module.hq.systems.HQInventory;
import com.dalonedrow.module.hq.systems.HQPlayer;
import com.dalonedrow.module.hq.systems.HQScript;
import com.dalonedrow.module.hq.ui.widgets.EquipmentDialog;
import com.dalonedrow.module.hq.ui.widgets.HQHeroViewer;
import com.dalonedrow.module.hq.ui.widgets.HQSpellPanel;
import com.dalonedrow.module.hq.ui.widgets.SpellFamilyChooserDialog;
import com.dalonedrow.pooled.PooledStringBuilder;
import com.dalonedrow.pooled.StringBuilderPool;
import com.dalonedrow.utils.UtilityMethods;

/**
 * @author Donald
 */
public final class CharacterChooserView implements View {
	/**
	 * the one and only instance of the <code>CharacterChooserView</code> class.
	 */
	private static CharacterChooserView	instance;
	/**
	 * Gives access to the singleton instance of {@link CharacterChooserView}.
	 * @return {@link CharacterChooserView}
	 */
	public static CharacterChooserView getInstance() {
		if (CharacterChooserView.instance == null) {
			CharacterChooserView.instance = new CharacterChooserView();
		}
		return CharacterChooserView.instance;
	}
	/** the list of Buttons for the characters. */
	private Button[]	btnChars;
	/** the okay button. */
	private Button		btnOkay;
	/** the button to reset all spells. */
	private Button		btnResetSpells;
	/** the description label. */
	private Label		lblDesc;
	/** the panel used to organize items. */
	private PagePanel	panel;
	/** flag indicating initialization has been completed. */
	private boolean		runInit	= false;
	/**
	 * Gets the panel containing the character buttons.
	 * @return {@link Panel}
	 */
	private Panel getCharButtonPanel() {
		Panel pnl = new LandscapePagePanel(Panel.LANDSCAPE_CENTER);
		btnChars = new Button[4];
		try {
			SpriteBase sb = new BasicSpriteObject();
			SpriteImageObject img =
					SpriteImageObjectFactory.getInstance().getImageByName(
							"zull_grey");
			sb.setImageRefId(img.getRefId());
			sb.setWidth(img.getWidth());
			sb.setHeight(img.getHeight());
			btnChars[0] = new Button(sb);
			btnChars[0].setHighlightBorder(new H1SelectionBorder());
			btnChars[0].addAction(new Action() {
				/**
				 * {@inheritDoc}
				 */
				@Override
				public void performAction() {
					try {
						// add call to load barbarian stats
						InputEvent.getInstance().addAction(
								CharacterChooserView.getInstance(), // object
								CharacterChooserView.class.getMethod(
										"showBarbarianInfo", null),
								null
								);
					} catch (Exception ex) {
						JOGLErrorHandler.getInstance().fatalError(ex);
					}
				}
			});
			pnl.addChild(btnChars[0]);
			pnl.addChild(UIFactory.getInstance().getSpacer(
					GlobalConstants.INT_050, GlobalConstants.INT_050));
			// dwarf
			sb = new BasicSpriteObject();
			img = SpriteImageObjectFactory.getInstance().getImageByName(
					"strom_grey");
			sb.setImageRefId(img.getRefId());
			sb.setWidth(img.getWidth());
			sb.setHeight(img.getHeight());
			btnChars[1] = new Button(sb);
			btnChars[1].setHighlightBorder(new H1SelectionBorder());
			btnChars[1].addAction(new Action() {
				/**
				 * {@inheritDoc}
				 */
				@Override
				public void performAction() {
					try {
						// add call to load barbarian stats
						InputEvent.getInstance().addAction(
								CharacterChooserView.getInstance(), // object
								CharacterChooserView.class.getMethod(
										"showDwarfInfo", null),
								null
								);
					} catch (Exception ex) {
						JOGLErrorHandler.getInstance().fatalError(ex);
					}
				}
			});
			pnl.addChild(btnChars[1]);
			pnl.addChild(UIFactory.getInstance().getSpacer(
					GlobalConstants.INT_050, 1));
			// elf
			sb = new BasicSpriteObject();
			img = SpriteImageObjectFactory.getInstance().getImageByName(
					"galadrus_grey");
			sb.setImageRefId(img.getRefId());
			sb.setWidth(img.getWidth());
			sb.setHeight(img.getHeight());
			btnChars[2] = new Button(sb);
			btnChars[2].setHighlightBorder(new H1SelectionBorder());
			btnChars[2].addAction(new Action() {
				/**
				 * {@inheritDoc}
				 */
				@Override
				public void performAction() {
					try {
						// add call to load barbarian stats
						InputEvent.getInstance().addAction(
								CharacterChooserView.getInstance(), // object
								CharacterChooserView.class.getMethod(
										"showElfInfo", null),
								null
								);
					} catch (Exception ex) {
						JOGLErrorHandler.getInstance().fatalError(ex);
					}
				}
			});
			pnl.addChild(btnChars[2]);
			pnl.addChild(UIFactory.getInstance().getSpacer(
					GlobalConstants.INT_050, 1));
			// wizard
			sb = new BasicSpriteObject();
			img = SpriteImageObjectFactory.getInstance().getImageByName(
					"akron_grey");
			sb.setImageRefId(img.getRefId());
			sb.setWidth(img.getWidth());
			sb.setHeight(img.getHeight());
			btnChars[3] = new Button(sb);
			btnChars[3].setHighlightBorder(new H1SelectionBorder());
			btnChars[3].addAction(new Action() {
				/**
				 * {@inheritDoc}
				 */
				@Override
				public void performAction() {
					try {
						// add call to load barbarian stats
						InputEvent.getInstance().addAction(
								CharacterChooserView.getInstance(), // object
								CharacterChooserView.class.getMethod(
										"showWizardInfo", null),
								null
								);
					} catch (Exception ex) {
						JOGLErrorHandler.getInstance().fatalError(ex);
					}
				}
			});
			pnl.addChild(btnChars[3]);
		} catch (Exception ex) {
			JOGLErrorHandler.getInstance().fatalError(ex);
		}
		return pnl;
	}
	/**
	 * Builds the first row.
	 * @return {@link GuiComponent}
	 */
	private GuiComponent getFirstRow() {
		PortraitPagePanel top =
				new PortraitPagePanel(Panel.PORTRAIT_CENTER);
		PooledStringBuilder sb =
				StringBuilderPool.getInstance().getStringBuilder();
		sb.append("Four  valiant  Heroes  have been summoned by Mhenn-Tohr\n");
		sb.append("the  good  and  ancient  sage, to do battle with Chaos.\n");
		sb.append("Theirs  is  the ultimate heroic challenge, descend into\n");
		sb.append("the  treacherous world of the unknown and restore honor\n");
		sb.append("to the Empire.  Destroy the evil forces of Chaos!\n\n");
		sb.append("Bonded by their loyalty to the Empire, the brave Heroes\n");
		sb.append("unite.   Stepping  cautiously,  they journey deeper and\n");
		sb.append("deeper into a dark, hidden world...\n\n");
		sb.append("Choose your Hero:");
		Label lbl = UIFactory.getInstance().getStandardH1Label(sb.toString());
		top.addChild(lbl);
		top.addChild(getCharButtonPanel());
		try {
			top.setBorder(UIFactory.getInstance().getVXStyleDialogBorder());
		} catch (Exception ex) {
			JOGLErrorHandler.getInstance().fatalError(ex);
		}
		sb.returnToPool();
		return top;
	}
	/**
	 * Gets the options panel, with the hero's description and the reset spells
	 * button.
	 * @return {@link Panel}
	 */
	private Panel getOptionsPanel() {
		Panel pnl = new PortraitPagePanel(Panel.PORTRAIT_CENTER);
		lblDesc = UIFactory.getInstance().getStandardH1Label(
				GlobalConstants.CLASS_DESCRIPTIONS[0]);
		lblDesc.setMaximumWidth(247);
		try {
			/*
			lblDesc.setBorder(BorderFactory.getInstance()
					.getBorderEdgeOf8ImagesBackgroundOf1Color(
							new int[] { 8, 8, 8, 8 },
							GlobalConstants.HQ_MONO_PANEL_BORDER,
							GlobalConstants.COL_HQ_MONO_DESC_BACKGROUND_A,
							3,
							3));
							*/
			lblDesc.setBorder(UIFactory.getInstance().getVXStyleDialogBorder());
		} catch (Exception ex) {
			JOGLErrorHandler.getInstance().fatalError(ex);
		}
		pnl.addChild(lblDesc);
		pnl.addChild(UIFactory.getInstance().getSpacer(
				1, GlobalConstants.INT_004));
		btnResetSpells = UIFactory.getInstance().getStandardH1Button(
				"Choose New Spells");
		btnResetSpells.setHighlightBorder(
				BorderFactory.getInstance().getHighlightBorder(
						btnResetSpells.getId(), "widget_highlight"));
		btnResetSpells.addAction(new Action() {
			/**
			 * {@inheritDoc}
			 */
			@Override
			public void performAction() {
				try {
					// show spell options
					InputEvent.getInstance().addAction(
							CharacterChooserView.getInstance(), // object
							CharacterChooserView.class.getMethod(
									"showSpellOptionsForPC", null),
							null
							);
				} catch (Exception ex) {
					JOGLErrorHandler.getInstance().fatalError(ex);
				}
			}
		});
		pnl.addChild(btnResetSpells);
		pnl.addChild(UIFactory.getInstance().getSpacer(
				1, GlobalConstants.INT_004));
		pnl.addChild(SpellFamilyChooserDialog.getInstance());
		return pnl;
	}
	/**
	 * {@inheritDoc}
	 */
	@Override
	public void handleMouseOver(final float x, final float y) {
		if (Interface.getInstance().hasViewFlag(
				GlobalConstants.VW_07_DLG_WINDOW)) {
			// the equipment dialog is being displayed.
			EquipmentDialog.getInstance().handleMouseOver(x, y);
		} else if (SpellFamilyChooserDialog.getInstance().isVisible()) {
			SpellFamilyChooserDialog.getInstance().handleMouseOver(x, y);
		} else {
			panel.handleMouseOver(x, y);
			if (!HQInventory.getInstance().contains(x, y)) {
				HQInventory.getInstance().clearHighlight();
			}
			if (!HQSpellPanel.getInstance().contains(x, y)) {
				HQSpellPanel.getInstance().clearHighlight();
			}
			try {
				int prof = -1;
				if (ProjectConstants.getInstance().getPCObject() != null) {
					prof = ((HQInteractiveObject) ProjectConstants
							.getInstance()
							.getPCObject()).getPCData().getProfession();
				}
				if (btnChars[0].contains(x, y)
						|| prof == GlobalConstants.CLASS_00BARBARIAN) {
					btnChars[0].getSprite().setImageRefId(
							SpriteImageObjectFactory.getInstance()
									.getImageRefId("ultima_barbarian_zull"));
					btnChars[0].onHighlight(true);
				} else {
					btnChars[0].getSprite().setImageRefId(
							SpriteImageObjectFactory.getInstance()
									.getImageRefId("zull_grey"));
				}
				if (btnChars[1].contains(x, y)
						|| prof == GlobalConstants.CLASS_01DWARF) {
					btnChars[1].getSprite().setImageRefId(
							SpriteImageObjectFactory.getInstance()
									.getImageRefId("ultima_dwarf_strom"));
					btnChars[1].onHighlight(true);
				} else {
					btnChars[1].getSprite().setImageRefId(
							SpriteImageObjectFactory.getInstance()
									.getImageRefId("strom_grey"));
				}
				if (btnChars[2].contains(x, y)
						|| prof == GlobalConstants.CLASS_02ELF) {
					btnChars[2].getSprite().setImageRefId(
							SpriteImageObjectFactory.getInstance()
									.getImageRefId("ultima_elf_galadrus"));
					btnChars[2].onHighlight(true);
				} else {
					btnChars[2].getSprite().setImageRefId(
							SpriteImageObjectFactory.getInstance()
									.getImageRefId("galadrus_grey"));
				}
				if (btnChars[GlobalConstants.INT_003].contains(x, y)
						|| prof == GlobalConstants.CLASS_03WIZARD) {
					btnChars[GlobalConstants.INT_003].getSprite()
							.setImageRefId(
									SpriteImageObjectFactory.getInstance()
											.getImageRefId(
													"ultima_wizard_akron"));
					btnChars[3].onHighlight(true);
				} else {
					btnChars[GlobalConstants.INT_003].getSprite()
							.setImageRefId(
									SpriteImageObjectFactory.getInstance()
											.getImageRefId("akron_grey"));
				}
			} catch (Exception ex) {
				JOGLErrorHandler.getInstance().fatalError(ex);
			}
		}
	}
	/**
	 * Initializes the {@link View}. Choose your character bar dwa ch explainer
	 * elf sor begin
	 * @throws Exception if an error occurs
	 */
	public void init() throws Exception {
		if (!runInit) {
			panel = new PortraitPagePanel(Panel.PORTRAIT_CENTER);
			// 1st row - text
			panel.addChild(getFirstRow());
			// 2nd row - buttons
			// panel.addChild(getCharButtonPanel());
			// 3rd row - char viewer and description
			LandscapePagePanel lp = new LandscapePagePanel(
					Panel.LANDSCAPE_TOP);
			lp.addChild(getOptionsPanel());
			lp.addChild(UIFactory.getInstance().getSpacer(40, 1));
			lp.addChild(HQHeroViewer.getInstance());
			panel.addChild(lp);
			// 4th row - okay button
			panel.addChild(UIFactory.getInstance()
					.getSpacer(1, GlobalConstants.INT_010));
			initOkayButton();
			panel.addChild(btnOkay);
			SimplePoint pt = UtilityMethods.getInstance()
					.centerComponentInFrame(
							panel);
			panel.setPosition(pt.getX(), pt.getY(), 0.0f);
			panel.setVisible(true);
			HQHeroViewer.getInstance().setVisible(false);
			btnOkay.setVisible(false);
			lblDesc.setVisible(false);
			btnResetSpells.setVisible(false);
			SpellFamilyChooserDialog.getInstance().setVisible(false);
			runInit = true;
		}
	}
	/** Initializes the Okay button. */
	private void initOkayButton() {
		btnOkay = UIFactory.getInstance().getStandardButton("Enter the Maze");
		btnOkay.setHighlightBorder(
				BorderFactory.getInstance().getHighlightBorder(btnOkay.getId(),
						"widget_highlight"));
		btnOkay.addAction(new Action() {
			/**
			 * {@inheritDoc}
			 */
			@Override
			public void performAction() {
				try {
					// show spell options
					InputEvent.getInstance().addAction(
							CharacterChooserView.getInstance(), // object
							CharacterChooserView.class.getMethod(
									"startMaze", null),
							null
							);
				} catch (Exception ex) {
					JOGLErrorHandler.getInstance().fatalError(ex);
				}
			}
		});
	}
	/**
	 * {@inheritDoc}
	 */
	@Override
	public boolean keyTyped(final char character) {
		switch (character) {
		case Keys.ESCAPE:
			System.out.println("esc");
			DawnQuestGame.getInstance().end();
			break;
		case Keys.UP:
			break;
		case Keys.DOWN:
			break;
		case Keys.ENTER:
			break;
		case Keys.TAB:
			break;
		case Keys.BACKSPACE:
			try {} catch (Exception ex) {
				JOGLErrorHandler.getInstance().fatalError(ex);
			}
			break;
		case Keys.SPACE:
			try {
				// textfield.addCharacter(e.getKeyChar());
			} catch (Exception ex) {
				JOGLErrorHandler.getInstance().fatalError(ex);
			}
			break;
		default:
			if (Character.isLetterOrDigit(character)) {
				try {
					// textfield.addCharacter(e.getKeyChar());
				} catch (Exception ex) {
					JOGLErrorHandler.getInstance().fatalError(ex);
				}
			}
			break;
		}
		return true;
	}
	/**
	 * {@inheritDoc}
	 */
	@Override
	public void prepareForRendering() throws Exception {
		if (!runInit) {
			try {
				init();
			} catch (Exception ex) {
				JOGLErrorHandler.getInstance().fatalError(ex);
			}
		}
		panel.prepareForRendering();
		if (Interface.getInstance().hasViewFlag(
				GlobalConstants.VW_07_DLG_WINDOW)) {
			// the equipment dialog is being displayed.
			EquipmentDialog.getInstance().prepareForRendering();
		}
	}
	private void releasePreviousPC() throws Exception {
		if (ProjectConstants.getInstance().getPcId() != -1) {
			// clear the old IO
			HQInteractiveObject old =
					(HQInteractiveObject) Interactive.getInstance().getIO(
							ProjectConstants.getInstance().getPcId());
			Interactive.getInstance().releaseIO(old);
			old = null;
		}
	}
	/** Shows the barbarian's stats. */
	public void showBarbarianInfo() {
		try {
			releasePreviousPC();
			HQInteractiveObject io =
					HQPlayer.getInstance().getFreshHero(new Zull());
			ProjectConstants.getInstance().setPc(io.getRefId());
			HQHeroViewer.getInstance().setPc(io);
			HQHeroViewer.getInstance().setVisible(true);
			btnOkay.setVisible(true);
			int prof = io.getPCData().getProfession();
			lblDesc.setText(GlobalConstants.CLASS_DESCRIPTIONS[prof]);
			lblDesc.setVisible(true);
			btnResetSpells.setVisible(false);
		} catch (Exception ex) {
			JOGLErrorHandler.getInstance().fatalError(ex);
		}
	}
	/** Shows the dwarf's stats. */
	public void showDwarfInfo() {
		try {
			releasePreviousPC();
			HQInteractiveObject io =
					HQPlayer.getInstance().getFreshHero(new Strom());
			ProjectConstants.getInstance().setPc(io.getRefId());
			HQHeroViewer.getInstance().setPc(io);
			HQHeroViewer.getInstance().setVisible(true);
			int prof = io.getPCData().getProfession();
			lblDesc.setText(GlobalConstants.CLASS_DESCRIPTIONS[prof]);
			lblDesc.setVisible(true);
			btnResetSpells.setVisible(false);
			btnOkay.setVisible(true);
		} catch (Exception ex) {
			JOGLErrorHandler.getInstance().fatalError(ex);
		}
	}
	/** Shows the elf's stats. */
	public void showElfInfo() {
		try {
			releasePreviousPC();
			HQInteractiveObject io =
					HQPlayer.getInstance().getFreshHero(new Galadrus());
			ProjectConstants.getInstance().setPc(io.getRefId());
			HQHeroViewer.getInstance().setPc(io);
			HQHeroViewer.getInstance().setVisible(true);
			int prof = io.getPCData().getProfession();
			lblDesc.setText(GlobalConstants.CLASS_DESCRIPTIONS[prof]);
			lblDesc.setVisible(true);
			SpellFamilyChooserDialog.getInstance().setNumAllowed(1);
			SpellFamilyChooserDialog.getInstance().setVisible(true);
			btnResetSpells.setVisible(true);
			btnOkay.setVisible(true);
		} catch (Exception ex) {
			JOGLErrorHandler.getInstance().fatalError(ex);
		}
	}
	/**
	 * Shows the spell options for a PC.
	 * @throws Exception if an error occurs
	 */
	public void showSpellOptionsForPC() throws Exception {
		HQInteractiveObject io =
				(HQInteractiveObject) Interactive.getInstance().getIO(
						ProjectConstants.getInstance().getPcId());
		io.getPCData().clearSpellsAvailable();
		io = null;
		SimplePoint pt = UtilityMethods.getInstance().centerComponentInFrame(
				SpellFamilyChooserDialog.getInstance());
		SpellFamilyChooserDialog.getInstance().setVisible(true);
		Interface.getInstance().showDialog(
				SpellFamilyChooserDialog.getInstance());
	}
	/** Shows the wizard's stats. */
	public void showWizardInfo() {
		try {
			releasePreviousPC();
			HQInteractiveObject io =
					HQPlayer.getInstance().getFreshHero(new Akron());
			ProjectConstants.getInstance().setPc(io.getRefId());
			HQHeroViewer.getInstance().setPc(io);
			HQHeroViewer.getInstance().setVisible(true);
			int prof = io.getPCData().getProfession();
			lblDesc.setText(GlobalConstants.CLASS_DESCRIPTIONS[prof]);
			lblDesc.setVisible(true);
			SpellFamilyChooserDialog.getInstance().setNumAllowed(
					GlobalConstants.INT_003);
			SpellFamilyChooserDialog.getInstance().setVisible(true);
			btnResetSpells.setVisible(true);
			btnOkay.setVisible(true);
		} catch (Exception ex) {
			JOGLErrorHandler.getInstance().fatalError(ex);
		}
	}
	/**
	 * Starts the first maze.
	 * @throws Exception if an error occurs
	 */
	public void startMaze() throws Exception {
		// set splash text
		PooledStringBuilder sb =
				StringBuilderPool.getInstance().getStringBuilder();
		sb.append("You wake on cold stone floor.  Your memory is ");
		sb.append("hazy, but you remember what Mhenn-Tohr said ");
		sb.append("to you before incanting the Spell of ");
		sb.append("Transposition:\n\"This will be your final ");
		sb.append("test before you set forth. Be sure to use all ");
		sb.append("the skills that you have been taught. You ");
		sb.append("must attempt to find your way out. Several ");
		sb.append("monsters have been placed in the Maze. They ");
		sb.append("will try to stop you, so take care. Whoever ");
		sb.append("finds his way to the exit stairs first will ");
		sb.append("be rewarded with 100 Gold Coins. This may be ");
		sb.append("used to buy Equipment for the adventures to ");
		sb.append("come.\"");
		DungeonSplashView.getInstance().setText(sb.toString());
		sb.returnToPool();
		// set map to load
		HQScript.getInstance().setGlobalVariable("currentMap",
				new Integer(0));
		HQScript.getInstance().setGlobalVariable("currentMapName",
				"maze0");
		// set the starting position

		// add call to load character chooser screen to input events
		((HQController) ProjectConstants.getInstance()).loadDungeonSplash();
	}
	/**
	 * {@inheritDoc}
	 */
	@Override
	public boolean touchUp(final int x, final int y, final int pointer,
			final int button) {
		if (Interface.getInstance().hasViewFlag(
				GlobalConstants.VW_07_DLG_WINDOW)) {
			// the equipment dialog is being displayed.
			if (button == Buttons.RIGHT) {
				// Right-click happened
				// hide the dialog
				EquipmentDialog.getInstance().hideDialog();
			} else if (EquipmentDialog.getInstance().contains(x, y)) {
				EquipmentDialog.getInstance().touchUp(x, y, pointer, button);
			} else {
				// hide the dialog
				EquipmentDialog.getInstance().hideDialog();
			}
		} else if (SpellFamilyChooserDialog.getInstance().isVisible()) {
			SpellFamilyChooserDialog.getInstance().touchUp(x, y, pointer,
					button);
		} else {
			panel.touchUp(x, y, pointer, button);
		}
		return true;
	}
}
